﻿using System;
using System.Collections.Generic;
using System.Text;

namespace JSONUtil
{
    public class JSONObject : IJSONObject
    {
        List<KeyValuePair<string, object>> members = new List<KeyValuePair<string, object>>();

        public List<KeyValuePair<string, object>> Members
        {
            get
            {
                return members;
            }
        }


        public bool MemberExists(string memberName)
        {
            return members.Exists((namevaluepair) => String.Equals(namevaluepair.Key, memberName));
        }

        public object this[string memberName]
        {
            get
            {
                KeyValuePair<string, object> member = members.Find((namevaluepair) => String.Equals(namevaluepair.Key, memberName));
                if (member.Key != null)
                    return member.Value;
                else
                    throw new KeyNotFoundException(String.Format("specified member '{0}' is not found in the current JSON Object", memberName));
            }
        }
    }

    /// <summary>
    /// just a marker.
    /// </summary>
    public interface IJSONObject
    {
    }
}
